package com.finiac.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;



import com.finiac.model.Student;

public class StudentDAOImpl implements StudentDAO {

private HibernateTemplate hibernateTemplate;
	
	public void setSessionFactory(SessionFactory sessionFactory){
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Student selectByAdmissionNo(long admissionNo) {
		Student student= new Student();
		List<Student> studentList= hibernateTemplate.find("from Student where admissionNo="+admissionNo +" and isActive =1");
		for(int i=0;i<studentList.size();i++)
		{
			student = studentList.get(i);
		}
		return student;
	}
	
	@Override
	public void saveStudent(Student student) {
		hibernateTemplate.saveOrUpdate(student);

}

	@SuppressWarnings("unchecked")
	@Override
	public List<Student> listStudent() {
		return hibernateTemplate.find("from Student where isActive =1");
	}
	

}
